package com.wqh.ice.demo;


import com.wqh.ice.service.HelloService;
import com.zeroc.Ice.Communicator;
import com.zeroc.Ice.Current;
import com.zeroc.Ice.Identity;
import com.zeroc.Ice.ObjectAdapter;
import com.zeroc.IceBox.Service;
import java.util.logging.Logger;

public class HelloServiceI implements HelloService ,Service{

    private Logger logger = Logger.getLogger(this.getClass().getSimpleName());
    private ObjectAdapter adapter;

    @Override
    public String sayHello(String s, Current current) {
        logger.info("开始调取服务");
        System.out.println("client message:"+s);
//        return "DIO:"+s;
        return "Hello,"+s;
    }


    @Override
    public void start(String s, Communicator communicator, String[] strings) {
        logger.info("name:"+s);
        //给传入的通信器创建适配器
        adapter = communicator.createObjectAdapter(s);
        //获取ice对象,将当前服务类对象servant提交给适配器
        Object servant = this;
        Identity identity = communicator.stringToIdentity(s);
        adapter.add((com.zeroc.Ice.Object)servant,identity);

        //激活适配器
        adapter.activate();

        logger.info("通信器适配器已经启动");
    }

    @Override
    public void stop() {
        logger.info("通信器适配器已经停止");
        adapter.destroy();
    }
}
